package com.zb.exceptions;

import com.alibaba.fastjson.JSON;
import com.zb.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BussinessException.class)
    public ResponseEntity<String> handleExcepting(BussinessException e){
        R r = new R(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(JSON.toJSONString(r));
    }
//    @ExceptionHandler(Exception.class)
//    public ResponseEntity<String> handleExcepting(Exception e){
//        log.error("error",e);
//        R r = new R(HttpStatus.INTERNAL_SERVER_ERROR.value(), "服务器内部错误");
//        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(JSON.toJSONString(r));
//    }
}
